/**	
 * <br>
 * Copyright 2011 Chuan. All rights reserved.<br>
 * <br>			 
 * Package: com.chuan.mantu <br>
 * FileName: ConfigActivity.java <br>
 * <br>
 * @version
 * @author javacyc@qq.com
 * @created 2012-11-27
 * @last Modified 
 * @history
 */

package com.chuan.mantu;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.chuan.mantu.sql.DBManager;
import com.chuan.mantu.utils.ConnectionDetector;
import com.chuan.mantu.utils.Const;

/**
 * {程序相关设置Activity}
 *  
 *  @author javacyc@qq.com
 *  @created 2012-11-27 下午03:18:27
 *  @lastModified       
 *  @history           
 */

public class ConfigActivity extends Activity {

	private CheckBox checkBox_23G;
	
	private DBManager dbManager;
	
	private ConnectionDetector connectionDetector;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.config);
		checkBox_23G = (CheckBox) findViewById(R.id.config_checkbox_23G);
		dbManager = new DBManager(this);
		if(dbManager.getConfig(Const.CONFIG_INTENET_MOBILE).equals("1")){
			checkBox_23G.setChecked(true);
		}
		connectionDetector = new ConnectionDetector(this);
		checkBox_23G.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked){
					dbManager.updateConfig(Const.CONFIG_INTENET_MOBILE, "1");
					Const.VALID_INTENET = connectionDetector.isConnection();
				}else{
					dbManager.updateConfig(Const.CONFIG_INTENET_MOBILE, "0");
					Const.VALID_INTENET = connectionDetector.isWifiConnection();
				}
			}
		});
		
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		dbManager.closeDB();
	}
}